package com.lcm.weam.entity.algo;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * 富营养化指数计算（扩展2项指标）
 */
@Data
public class EutrophicationEva {
    private String name; //名称
    private Double permanganateIndex; //高猛酸盐指数
    private Double chla; //叶绿素a
    private Double SD; //透明度
    private Double TP; //总磷
    private Double TN; //总氮
    private Double value; //综合营养状态指数
    private Integer num; //指标个数
    public void doEva(){
        double vvalue = 0.0; //赋值给value
        List<Double> ws = new ArrayList<>(); //权重
        List<Double> vs = new ArrayList<>(); //每种营养状态指数
        if(chla != null){
            vs.add( 10*(2.5+1.086*Math.log(chla)) );
            ws.add( 1.0 );
        }
        if (TP != null){
            vvalue += 10*(9.436+1.624*Math.log(TP));
            ws.add( 0.7056 );
        }
        if (TN != null){
            vvalue += 10*(5.453+1.694*Math.log(TN));
            ws.add( 0.6724 );
        }
        if (SD != null){
            vvalue += 10*(5.118+1.94*Math.log(SD));
            ws.add( 0.6889 );
        }
        if (permanganateIndex != null){
            vvalue += 10*(2.5+1.086*Math.log(permanganateIndex));
            ws.add( 0.6889 );
        }
        if (!ws.isEmpty()){
            double sum = 0.0;
            for (double s : ws){
                sum += s;
            }
            for (int i = 0; i < ws.size(); i++) {
                //vs和ws索引一一对应
                vvalue += (ws.get(i)/sum)*vs.get(i);
            }
        }
        this.value = vvalue;
        this.num = ws.size();
    }
}

